import store from "@/store.js";

export default async function (
    url,
    method,
    data,
    useAuth,
    isFileDownload,
    isFormData
){

    url = "http://localhost:8000/" + url
    let responseBody = {
        method: method,
        headers: {},
    }

    if (method !== "GET") {
        responseBody.headers = {
            "Content-Type": "application/json",
        }
        responseBody.body = JSON.stringify(data)
    }




    if (isFormData) {
        responseBody.body = data
        responseBody.headers = {}

    }

    if (useAuth) {
        responseBody.headers.Authorization = `Token ${store.state.token}`
    }

    let response = await fetch(url,responseBody)

    if (isFileDownload) {
        return response
    }



    let message = await response.json()

    return {
        status: response.status,
        message: message
    }
};